package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.HeSuan;
import com.example.entity.Vaccine;
import com.example.service.VaccineService;
import com.example.vo.DataView;
import com.example.vo.HeSuanVo;
import com.example.vo.VaccineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/vaccine")
public class VaccineController {

    @Autowired
    private VaccineService vaccineService;

    @RequestMapping("/loadAllVaccine")
    public DataView loadAllVaccine(VaccineVo vaccineVo){
        IPage<Vaccine> page=new Page<>(vaccineVo.getPage(), vaccineVo.getLimit());
        QueryWrapper<Vaccine> queryWrapper=new QueryWrapper<>();
        vaccineService.page(page,queryWrapper);
        return new DataView(page.getTotal(),page.getRecords());
    }

    @RequestMapping({"/addVaccine","/updateVaccine"})
    public DataView addOrUpdateVaccine(Vaccine vaccine){
        vaccineService.saveOrUpdate(vaccine);
        DataView dataView=new DataView();
        dataView.setCode(200);
        dataView.setMsg("操作成功");
        return dataView;
    }

    @RequestMapping("/deleteVaccine")
    public DataView deleteVaccine(Integer id){
        vaccineService.removeById(id);
        DataView dataView=new DataView();
        dataView.setCode(200);
        dataView.setMsg("删除成功");
        return dataView;
    }
}
